﻿using System;
using System.ComponentModel;
using System.Diagnostics;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Xml;

namespace System.ServiceModel
{
    public interface ICustomSoapHeaderProvider
    {
        string Name { get; }
        string Namespace { get; }
        object Value { get; }
    }

    public class HeaderMessageInspector : IClientMessageInspector
    {
        private readonly ICustomSoapHeaderProvider _provider;

        public HeaderMessageInspector(ICustomSoapHeaderProvider provider)
        {
            Debug.Assert(provider!=null);
            this._provider = provider;
        }

        public object BeforeSendRequest(ref Message request, IClientChannel channel)
        {
            request.Headers.Add(MessageHeader.CreateHeader(_provider.Name, _provider.Namespace, _provider.Value));
            
            return null;
        }

        public void AfterReceiveReply(ref Message reply, object correlationState)
        {
        }
    }

}